package datasv.framework_datasv;

import java.util.ArrayList;
import java.util.List;

import data.datafactory.DatabaseOperator;
import po.SubModelPO;

public class GetAllSubModel {
	public static void main(String[] args) {
		System.out.println(new GetAllSubModel().getAllSubModelOfModel("001", "0010102"));
	}
	public List<SubModelPO> getAllSubModelOfModel(String collegeID, String modelID){
		return getInSql(collegeID, modelID);
	}
	private List<SubModelPO> getInSql(String collegeID, String modelID){
		DatabaseOperator op=new DatabaseOperator("college"+collegeID);
		ArrayList<SubModelPO> list=new ArrayList<SubModelPO>();
		if(!op.ifDatabaseExist()||!op.ifFormExist("plan_submodel_list_"+modelID)){
			return list;
		}
	
		ArrayList<String> id=op.getColumn("plan_submodel_list_"+modelID,"id");
		if(id==null||id.isEmpty()){
			return list;
		}
		for (int i = 0; i < id.size(); i++) {
			String category=op.getOneInform(id.get(i), "plan_submodel_list_"+modelID, "category");
			String name=op.getOneInform(id.get(i), "plan_submodel_list_"+modelID, "name");
			int hS=Integer.parseInt(op.getOneInform(id.get(i), "plan_submodel_list_"+modelID, "headSemester"));
			int tS=Integer.parseInt(op.getOneInform(id.get(i), "plan_submodel_list_"+modelID, "tailSemester"));
			int headCredit=Integer.parseInt(op.getOneInform(id.get(i), "plan_submodel_list_"+modelID, "headCredit"));
			int tailCredit=Integer.parseInt(op.getOneInform(id.get(i), "plan_submodel_list_"+modelID, "tailCredit"));
			
			list.add(new SubModelPO(id.get(i), category, name, hS, tS, headCredit, tailCredit));
		}
		return list;
		
	}
}
